package org.rc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.rc.dto.MicPageDto;
import org.rc.entity.Mic;
import org.rc.mapper.MicMapper;
import org.rc.service.MicService;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class MicServiceImpl extends ServiceImpl<MicMapper, Mic> implements MicService {

    @Override
    public Mic getByMicId(Long id) {
        return this.getById(id);
    }

    @Override
    public void addMic(Mic mic) {
        this.save(mic);
    }

    @Override
    public void updateByMicId(Mic mic) {
        this.updateById(mic);
    }

    @Override
    public Page<Mic> getMicPage(MicPageDto micPageDto) {
        Page<Mic> page = new Page<>(micPageDto.getPageNo(),micPageDto.getPageSize());
        QueryWrapper<Mic> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotEmpty(micPageDto.getName()),"name",micPageDto.getName());
        return this.baseMapper.selectPage(page,queryWrapper);
    }

    @Override
    public List<Mic> getByMicIds(List<Long> ids) {
        return listByIds(ids);
    }

    @Override
    public void deleteById(Long id) {
        this.removeById(id);
    }

    @Override
    public void batchDeleteMic(List<Long> ids) {
        this.removeByIds(ids);
    }

    @Override
    public List<Mic> getAllMics() {
        return list();
    }
}
